# -*- coding: utf-8 -*-

from django.http import HttpResponse
from django.shortcuts import get_object_or_404,render
from Blogs.models import Blog,Tag
from markdown import markdown
from Blogs.visit_info import change_info

def main(request):
	context={}
	context['head_mainpage']='active'
	return render(request,'main.html',context)
	
def blog(request):
	context={}
	context['head_blog']='active'
	taglist=Tag.objects.all()
	
	context['taglist']=taglist
	bloglist=Blog.objects.order_by('-id')
	context['bloglist']=bloglist
	return render(request,'blog.html',context)
	
def links(request):
	context={}
	context['head_links']='active'
	return render(request,'links.html',context)
	
def message(request):
	context={}
	context['head_message']='active'
	return render(request,'message.html',context)
	
def article(request,aid):
	blog=get_object_or_404(Blog,id=aid)
	change_info(request,blog)
	blog.content=markdown(blog.content)
	context={}
	context['p']=blog
	context['head_blog']='active'
	if 'HTTP_REFERER' in request.META:
		context['referer']=request.META['HTTP_REFERER']
	else:
		context['referer']=request.get_host()+'/blog'
	return render(request,'article.html',context)
	
def linksgo(requests,ename):
	return HttpResponse('hiahiahia')
	
def tag(requests,tagid):
	tag=get_object_or_404(Tag,id=tagid)
	context={}
	context['tag']=tag
	context['head_blog']='active'